package service.impl;

import dao.MakeDao;
import dao.PatientDao;
import dao.RegisterDao;
import dao.ScheduleDao;
import entity.Make;
import entity.Patient;
import entity.Schedule;
import org.springframework.stereotype.Service;
import service.MakeService;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

@Service("makeService")
public class MakeServiceImpl implements MakeService {
    @Resource(name = "makeDao")
    MakeDao makeDao;

    @Resource(name = "scheduleDao")
    ScheduleDao scheduleDao;

    @Resource(name = "patientDao")
    PatientDao patientDao;

    @Resource(name = "registerDao")
    RegisterDao registerDao;
    @Override
    public Map<String, Object> GetMakeInfo(Map<String,Object> map) {
        Map<String,Object> map1=new HashMap<String, Object>();
        map1.put("total",makeDao.GetTotal(map));
        map1.put("rows",makeDao.GetAllMake(map));
        return map1;
    }
    @Override
    public Map<String, Object> GetSchedule(Map<String, Object> map) {
        Map<String,Object> map1=new HashMap<String, Object>();
        map1.put("rows",scheduleDao.GetAllYiShengInfo(map));
        map1.put("total",scheduleDao.GetCountByYisheng(map));
        return map1;
    }

    @Override
    public List<Schedule> GetMakeByDoctorId(int Pid) {
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
        String Date=format.format(new Date());
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("pid",Pid);
        map.put("date",Date);
        return scheduleDao.GetScheduleByDoctorId(map);
    }

    @Override
    public Patient GetUserInfoByid(int id) {
     return patientDao.GetPatientById(id);
    }

    @Override
    public boolean AddMake(Map<String, Object> map) {
        String id=((String)map.get("id"));
        int pid=(int) map.get("pId");
       Schedule schedule=(Schedule)map.get("schedule");
        Make make=new Make();
        make.setcFirstDate(schedule.getStarTime());
        make.setcLastDate(schedule.getEndTime());
        make.setnId(schedule.getnId());
        make.setcRemarks(schedule.getScheduleMatter());
        make.setpId(pid);
     if(scheduleDao.AddSchedule(schedule)>0){
           if(makeDao.AddMake(make)>0){
             return  registerDao.Upstat(id)>0?true:false;
         }
       }
        return false;
    }

}
